package com.easygem.controller.front;

import com.easygem.common.annotation.ControllerEndpoint;
import com.easygem.common.error.SystemException;
import com.easygem.common.response.ResponseBean;
import com.easygem.common.vo.front.ClientStatusVo;
import com.easygem.front.service.ClientStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author luoxi
 * @version 1.0
 * @className ClientStatusController
 * @Description 客户状态控制层
 * @date 2024/12/26 21:33
 */
@Api(tags = "客户状态")
@RestController
@RequestMapping("/system/clientStatus")
public class ClientStatusController {
    @Autowired
    private ClientStatusService clientStatusService;
    /**
     * 所有客户状态
     * @return
     */
    @ApiOperation(value = "所有客户状态")
    @GetMapping("/findAll")
    @ResponseBody
    public ResponseBean<List<ClientStatusVo>> findAll(@RequestParam(value = "accountName", defaultValue = "") String accountName) {
        List<ClientStatusVo> clientStatusVos = clientStatusService.getClientStatusAll(accountName);
        return ResponseBean.success(clientStatusVos);
    }
    /**
     * 客户状态下拉列表框
     *
     * @return
     */
    @ApiOperation(value = "客户状态列表", notes = "通过客户状态id查询")
    @GetMapping("/findList")
    @ResponseBody
    public ResponseBean<List<ClientStatusVo>> findList(@RequestParam(value = "accountName", defaultValue = "") String accountName) {
        List<ClientStatusVo> clientStatusVos = clientStatusService.getClientStatusListByEnable(accountName);
        return ResponseBean.success(clientStatusVos);
    }
    /**
     * 添加客户状态
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "添加客户状态失败", operation = "添加客户状态")
    @RequiresPermissions({"DataDictionary:add"})
    @ApiOperation(value = "添加客户状态")
    @PostMapping("/add")
    @ResponseBody
    public ResponseBean add(@RequestBody @Validated ClientStatusVo clientStatusVo) {
        clientStatusService.add(clientStatusVo);
        return ResponseBean.success();
    }


    /**
     * 编辑客户状态
     *
     * @param id 编号
     * @return
     */
    @ApiOperation(value = "编辑客户状态")
    @RequiresPermissions({"DataDictionary:edit"})
    @GetMapping("/edit/{id}")
    @ResponseBody
    public ResponseBean edit(@PathVariable Integer id) throws SystemException {
        ClientStatusVo clientStatusVo = clientStatusService.edit(id);
        return ResponseBean.success(clientStatusVo);
    }

    /**
     * 更新客户状态操作
     *
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "更新客户状态失败", operation = "更新客户状态")
    @ApiOperation(value = "更新客户状态")
    //@RequiresPermissions({"clientStatus:update"})
    @PutMapping("/update/{id}")
    @ResponseBody
    public ResponseBean update(@PathVariable Integer id, @RequestBody @Validated ClientStatusVo clientStatusVo) throws SystemException {
        clientStatusService.update(id,clientStatusVo);
        return ResponseBean.success();
    }
}
